<template>
  <div id="questions">
    <div>
      <el-button @click="delhot('删除')">删除</el-button>
      <el-button @click="searchshow = !searchshow">搜索&nbsp;<i class="iconfont icon-zhankai" :class="{active: searchshow === true}" style="font-size: 12px"></i></el-button>
    </div>
    <el-collapse-transition>
      <div v-show="searchshow">
        <div class="main-box">
          <el-input
            placeholder="请输入用户昵称"
            size="mini"
            prefix-icon="el-icon-search"
            v-model="searchmsg">
          </el-input>
          <span style="margin-left: 20px"><el-button size="mini" @click="search">确定</el-button></span>
        </div>
      </div>
    </el-collapse-transition>
    <msg-list :tableData="tableData" :title="title" :btntype="btntype" :pagesall="parseInt(pagesall)" :pages="parseInt(page)" @getselect="getselect" @changepage="changepage1" @getid="getid1"></msg-list>
    <div class="layer" v-show="delshow">
      <div class="mask" @click="delshow = false"></div>
      <div class="content">
        <span class="close" @click="delshow = false"><i class="iconfont icon-untitled94"></i></span>
        <p class="title" v-show="type">删除的理由</p>
        <p class="title" v-show="!type">屏蔽的理由</p>
        <div class="doit">
          <div class="one">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 20}"
              v-model="deletes.reason">
            </el-input>
          </div>
          <div class="buttons">
            <el-button size="mini" @click="deleteanswer">确定</el-button>
            <el-button size="mini" @click="delshow = false">取消</el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="layer" v-show="seecontent">
      <div class="mask" @click="seecontent = false"></div>
      <div class="content">
        <span class="close" @click="seecontent = false"><i class="iconfont icon-untitled94"></i></span>
        <p class="title">内容详情</p>
        <div>{{content}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import msgbox from '@/common/msgbox.js'
import MsgList from '../public/msgList'
import editor from '../../assets/editor/content'

export default {
  components: {
    MsgList,
    editor: editor},
  name: 'questions',
  data () {
    return {
      page: this.$route.params.page,
      status: '',
      searchmsg: '',
      btntype: ['内容详情'],
      pagesall: 0,
      content: {},
      type: true,
      deletes: {
        ids: [],
        reason: ''
      },
      delshow: false,
      searchshow: false,
      seecontent: false,
      title: [
        {
          prop: 'id',
          label: 'id'
        },
        {
          prop: 'content',
          label: '回复内容简介'
        },
        {
          prop: 'add_time',
          label: '发布时间'
        },
        {
          prop: 'username',
          label: '用户名'
        },
        {
          prop: 'nickname',
          label: '用户昵称'
        }
      ],
      tableData: [],
      intro: []
    }
  },
  mounted () {
    this.search()
  },
  methods: {
    search () {
      let that = this
      this.$g.ajax({
        path: 'Articlereplycomments/index/' + that.$route.params.id + '/' + that.page,
        method: 'post',
        data: {
          nickname: that.searchmsg
        },
        cbSuccess: function (data) {
          that.tableData = data.memo.list
          that.page = parseInt(data.memo.page)
          that.pagesall = parseInt(data.memo.pageTotal)
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    changepage1 (page) {
      this.page = page
      this.search()
    },
    delhot (type) {
      if (this.deletes.ids.length < 1) {
        this.$message({
          type: 'error',
          message: '请选择需要操作的数据'
        })
      } else {
        this.$confirm('确定' + type + '选中的评论吗?', '提示', {
          confirmButtonText: type,
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.delshow = true
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消' + type
          })
        })
      }
    },
    getid1 (val) {
      if (val.btn === '内容详情') {
        this.seecontent = true
        this.content = val.val.content
      }
    },
    getselect (vals) {
      this.deletes.ids = []
      for (let i in vals) {
        this.deletes.ids.push(vals[i].id)
      }
    },
    deleteanswer () {
      if (this.deletes.reason.length > 255) {
        this.$message.error('理由请控制在255字段以内')
      } else {
        let that = this
        let msg = that.deletes
        this.$g.ajax({
          path: 'Articlereplycomments/delete',
          method: 'post',
          data: msg,
          cbSuccess: function (data) {
            that.delshow = false
            for (let i in msg.ids) {
              for (let j in that.tableData) {
                if (parseInt(msg.ids[i]) === parseInt(that.tableData[j].id)) {
                  that.tableData.splice(j, 1)
                }
              }
            }
            that.$message.success('删除成功')
            that.deletes.reason = ''
          },
          cbError: function (data) {
            let msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .active{
    display: inline-block;
    -moz-transform:rotate(180deg);
    -webkit-transform:rotate(180deg);
    -o-transform:rotate(180deg);
    -ms-transform:rotate(180deg);
    transform:rotate(180deg);
  }
  #questions {
    .main-box{
      margin-top: 20px;
      span{
        margin-right: 30px;
        font-size: 14px;
        font-weight: 700;
        color: #606266;
      }
      .el-input {
        width: 240px;
      }
    }
    .main-box {
      .el-radio__inner {
        background: red;
      }
      .el-radio__input.is-checked+.el-radio__label{
        color: #00a4a0!important;
      }
    }
    .layer {
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      z-index: 999;
      .mask {
        background: rgba(153, 153, 153, 0.5);
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 1;
      }
      .content {
        position: relative;
        width: 640px;
        background: #fff;
        margin: 10% auto;
        z-index: 2;
        padding: 30px;
        .close {
          position: absolute;
          right: 10px;
          top: 10px;
          cursor: pointer;
        }
        .title {
          text-align: center;
          font-size: 18px;
          font-weight: bold;
        }
        .doit .one .el-input {
          width: 200px;
          margin-left: 20px;
        }
        .doit .one {
          margin-top: 20px;
          font-size: 14px;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
          position: relative;
          left: -4px;
        }
        .buttons {
          margin-top: 20px;
          text-align: center;
          button {
            margin: 0 20px;
          }
        }
      }
    }
  }
</style>
<style scoped>
  .el-button:focus, .el-button:hover{
    color: #00a4a0;
  }
  .el-button:active{
    border-color: #00a0a0;
  }
  .el-button{
    padding: 8px 14px;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
    background: #00a4a0;
    border-color: #00a4a0;
  }
  .transition-box {
    margin-bottom: 10px;
    width: 200px;
    height: 100px;
    border-radius: 4px;
    background-color: #409EFF;
    text-align: center;
    color: #fff;
    padding: 40px 20px;
    box-sizing: border-box;
    margin-right: 20px;
  }
</style>
